class Solution:
    def threeSumClosest(self, nums: List[int], target: int):
        nums.sort()
        target1=nums[0]+nums[1]+nums[2]
        for i in range(len(nums)-1):
            b=i+1
            c=len(nums)-1
            while b<c:
                target2=nums[i]+nums[b]+nums[c]
                if target2==target:
                    return target2
                if target2<target:
                    b+=1
                else:
                    c-=1                    
                if abs(target1-target)>abs(target2-target):
                    target1= target2
        return target1